<template>
  <div class="zh-video-list">
    <nav-header></nav-header>
    <div class="zh-table">
      <div class="zh-table-open clear">
        <div class="zh-open-left fl">
          <div class="open-width" style="width: 150px" v-if="$store.state.checkLevel">
            <!-- 多级-->
            <el-select v-if="$store.state.platformInformation" v-model="platform_id" filterable placeholder="教育局/学校">
              <el-option v-for="item in schoolcodeData" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
            <el-cascader placeholder="组织架构选择" v-else v-model="valueData" :options="allList" :props="optionProps">
            </el-cascader>
          </div>
          <div v-else style="display: inline-block">
            <!-- 单机-->
            <div class="open-width" style="width: 100px">
              <el-select v-model="listParam.study_section_id" filterable placeholder="请选择">
                <el-option v-for="item in orgLevel2" :key="item.id" :label="item.name" :value="item.id">
                </el-option>
              </el-select>
            </div>
            <div class="open-width" style="width: 100px">
              <el-select v-model="listParam.grade_id" filterable placeholder="请选择">
                <el-option v-for="item in orgLevel3" :key="item.id" :label="item.name" :value="item.id">
                </el-option>
              </el-select>
            </div>
            <div class="open-width" style="width: 100px">
              <el-select v-model="listParam.subject_id" filterable placeholder="请选择">
                <el-option v-for="item in orgSubject" :key="item.id" :label="item.name" :value="item.id">
                </el-option>
              </el-select>
            </div>
          </div>
          <div class="open-width" style="width: 120px" v-if="$store.state.checkLevel">
            <el-select v-model="listParam.cate_id" filterable placeholder="全部类型">
              <el-option v-for="item in typeOption" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </div>
          <div class="open-width" style="width: 120px"
            v-if="$store.state.checkLevel && !$store.state.platformInformation">
            <el-select v-model="listParam.status_m3u8" filterable placeholder="选择状态">
              <el-option label="选择状态" :value="-1"></el-option>
              <el-option label="已发布" :value="1"></el-option>
              <el-option label="转码中" :value="0"></el-option>
            </el-select>
          </div>
          <div class="open-width">
            <el-input v-model="listParam.keyword" placeholder="视频名称、授课教师" @keyup.enter.native="searchFunc"></el-input>
          </div>
          <el-button type="primary" @click="searchFunc">搜索</el-button>
          <el-button type="primary" @click="reset">重置</el-button>
        </div>
        <div class="zh-open-right fr">
          <el-button type="text" @click="toLink('/resources/video/video-push-history')"
            v-if="$store.state.checkLevel && !isTopEducation">推送历史</el-button>
          <el-button type="primary" @click="videoAdd">添加视频</el-button>
          <template v-if="$store.state.checkLevel">
            <!-- <el-button type="primary" v-if="user_level === 0" @click="pushLowAll">批量推下级</el-button> -->
            <!-- <el-button type="primary" v-if="platform" @click="pushUpAll">批量推上级</el-button> -->
            <el-button type="primary" v-show="!isTopEducation" @click="pushUpAll">批量推上级</el-button>
          </template>
          <!-- <el-button type="primary" @click="batchAdd">批量上传</el-button> -->
          <el-button type="danger" @click="deleteConfirm">批量删除</el-button>
        </div>
      </div>
      <div class="zh-table-contents" v-loading="loading.status" :element-loading-text="loading.txt">
        <el-table :data="listData" border max-height="541" @selection-change="handleSelectionChange"
          style="width: 100%">
          <el-table-column type="selection" width="50" fixed> </el-table-column>
          <el-table-column prop="video_name" label="视频名" align="center" show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="category" label="组织架构" align="center" show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="user_name" label="教师" align="center" show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="cate_name" label="视频分类" align="center" show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="size" label="大小" align="center" show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="create_time" label="发布时间" align="center" show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="" label="保存时间" align="center" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ getMonth(scope.row.save_month) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="" label="状态" align="center" show-overflow-tooltip>
            <template slot-scope="scope">
              <span v-if="scope.row.status_m3u8 == 1">已发布</span>
              <span v-if="scope.row.status_m3u8 == 0" style="color: #e6a23c">转码中</span>
            </template>
          </el-table-column>
          <el-table-column prop="upload_type" label="类型" align="center" show-overflow-tooltip>
            <template slot-scope="scope">
              <span v-if="scope.row.upload_type == 0">自主手动上传</span>
              <span v-if="scope.row.upload_type == 1">录播主机上传</span>
              <span v-if="scope.row.upload_type == 2">AI视频</span>
            </template>
          </el-table-column>
          <el-table-column prop="" label="操作" align="center" width="340" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-button :disabled="scope.row.status == 4" @click="videoEdit(scope.row)" type="text">编辑</el-button>
              <el-button :disabled="scope.row.status == 4" @click="videoView(scope.row)" type="text">预览</el-button>
              <el-button :disabled="scope.row.status == 4" @click="down(scope.row.id)" type="text">下载</el-button>
              <el-button :disabled="scope.row.status == 4" @click="pushIndexBox(scope.row)" type="text">推首页</el-button>
              <template v-if="$store.state.checkLevel">
                <el-button :disabled="scope.row.status == 4" @click="pushUpTrigger(scope.row)" v-show="!isTopEducation"
                  type="text">推上级</el-button>
                <!-- <el-button :disabled="scope.row.status == 4" v-if="platform" @click="pushUpTrigger(scope.row)" type="text">推上级</el-button> -->
                <!-- <el-button :disabled="scope.row.status == 4" v-if="user_level === 0" @click="pushLow(scope.row)" type="text">推下级</el-button> -->
              </template>
              <el-button :disabled="scope.row.status == 4" @click="deleteVideo_confirm(scope.row)" type="text"
                class="delete-button">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="table-pagination" v-show="total_number > 10">
          <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :current-page="listParam.page_index" :page-sizes="[10, 20, 30, 40, 50, 100]"
            :page-size="listParam.page_size" layout="total, sizes, prev, pager, next, jumper" :total="total_number">
          </el-pagination>
          <div class="pagination-button">
            <el-button @click="getList" type="primary" icon="el-icon-refresh" circle title="刷新数据" size="mini">
            </el-button>
          </div>
        </div>
      </div>
    </div>

    <transition name="el-fade-in-linear">
      <div class="masking" :class="{ activeLive: isActive }">
        <div class="maskingBox">
          <div class="masking_h">
            <span>视频预览</span>
            <i class="el-icon-close" @click="viewClose"></i>
          </div>
          <div class="masking_ccc">
            <!-- <videoAlertView
              v-if="showVideoPlayer"
              :playParam.sync="playParam"
            ></videoAlertView> -->
            <dplayer v-if="showVideoPlayer" :playParam.sync="playParam"></dplayer>
          </div>
        </div>
      </div>
    </transition>

    <el-dialog title="提示" :visible.sync="memoryVisible" :close-on-click-modal="false" :close-on-press-escape="false"
      width="400px">
      <div class="server-memory">
        <img src="./../../../../static/image/home/server.png" />
        <span>服务器内存容量不足20%，请尽快清理内存。可清理视频、录制文件及回收站</span>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="memoryVisible = false">我知道了</el-button>
      </div>
    </el-dialog>

    <!-- <el-dialog
            title="提示"
            :visible.sync="diskVisible"
            :close-on-click-modal="false"
            :close-on-press-escape="false"
            width="400px">
            <div class="server-memory">
                <img src="./../../../../static/image/home/server.png">
                <span>系统存储容量小于5G，请清理存储空间（视频/资源文件）或升级存储</span>
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="diskVisible = false">我知道了</el-button>
            </div>
        </el-dialog> -->

    <!-- 推首页 -->
    <el-dialog title="首页展示" :visible.sync="homeVisible" width="800px" custom-class="home-page"
      :close-on-click-modal="false">
      <div class="home-page-c">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px">
          <!-- <div class="home-page-t">
						请选择首页位置：<span>专辑 《{{pushObj.name}}》将放置在 “位置{{ruleForm.selectIndex+1}}”</span>
					</div> -->
          <el-form-item label-width="0" prop="selectIndex">
            <el-radio-group v-model="ruleForm.selectIndex">
              <el-radio v-for="(item, inx) in positionData" @change="renderPushHtml()" :key="inx" :label="inx"
                class="page-checked">
                <div class="home-page-ls">
                  <div>
                    <img :src="BASE_URL + item.picture" />
                    <i class="el-icon-error" v-if="parseInt(item.id) > 0 &&
            parseInt(pushObj.resid) != parseInt(item.resid)
            " @click.prevent="deletePushIndex(inx)"></i>
                  </div>
                  <p>位置{{ inx + 1 }}</p>
                </div>
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label-width="0">
            <el-button @click="pushToTop()">首页置顶</el-button>
            <el-button @click="resetForm('ruleForm')" type="primary" plain>重置</el-button>
            <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
          </el-form-item>
        </el-form>
      </div>
      <!-- <div slot="footer" class="dialog-footer"></div> -->
    </el-dialog>

    <!-- 推下级begin -->
    <el-dialog title="推下级" :visible.sync="pushLowFlag" v-if="pushLowFlag" width="600px" v-loading="loading.status"
      :element-loading-text="loading.txt" :close-on-click-modal="false">
      <push-low-win @listenPushLow="getPushLowList"></push-low-win>
      <span slot="footer" class="dialog-footer">
        <el-button @click="pushActive()">取 消</el-button>
        <el-button type="primary" @click="pushActive(1)">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 推下级end -->
    <!-- 推上级start -->
    <el-dialog title="推上级" :visible.sync="pushUpFlag" :close-on-click-modal="false" :close-on-press-escape="false"
      width="40%">
      <span style="padding-left: 10px; display: block; margin-bottom: 30px">推送的视频需要上级审核才能通过展示，是否确认将{{
            videoForm.video_name
          }}推送到上级教育局平台？</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="pushUpTips()">取 消</el-button>
        <el-button type="primary" @click="pushUpTips(1)">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 推上级end -->
  </div>
</template>
<script>
import videoAlertView from "../../public/videoAlertView";
import dplayer from "@/components/public/dplayer.vue";
import pushLowWin from "@/components/common/push-low-win";
export default {
  data() {
    return {
      allList: [], // 数据处理最终结果
      valueData: [], // 学段/年级/科目id
      app_code: sessionStorage.getItem("CheckSchoolAppCode"),
      isTopEducation: sessionStorage.getItem('CheckSchoolAppCode') === '00000000000000000000000000000000',
      optionProps: {
        value: "grade_id",
        label: "name",
      },
      status_m3u8: -1,
      type: -1,
      videoForm: {
        video_name: "",
      },
      video_id: "",
      pushUpFlag: false, //推上级弹窗状态
      loading: {
        status: false,
        txt: "获取数据...",
      },
      memoryVisible: false, // 服务器内存提示
      isActive: true,
      listData: [],
      listParam: {
        cate_id: 0,
        platform_id: null,
        study_section_id: null,
        grade_id: null,
        subject_id: null,
        keyword: "",
        page_index: 1,
        page_size: 10,
        status_m3u8: -1,
      },
      study_section_id: null,
      grade_id: null,
      subject_id: null,
      keyword: "",
      cate_id: "",
      orgLevel2Param: {
        //获取学段参数
        level: 2,
        pid: null,
        direction: "balance",
      },
      orgLevel3Param: {
        //获取年级参数
        level: 3,
        pid: null,
        direction: "balance",
      },
      orgLevel2: [],
      orgLevel3: [],
      orgSubject: [],
      subjectParam: {
        //获取科目,版本，参数
        type: 2,
        org_id: null,
        status: 1,
      },
      total_number: 0,
      typeOption: [],
      positionData: [],
      tempPositionData: [],
      homeVisible: false,
      ruleForm: {
        selectIndex: null,
      },
      rules: {
        selectIndex: [
          {
            required: true,
            type: "number",
            message: "请选择一个位置",
            trigger: "change",
          },
        ],
      },
      pushObj: {},
      home_flag: 1,
      showVideoPlayer: false,
      playParam: { play_url: "", type: 'application/x-mpegURL' },
      pushLowFlag: false /*推下级弹窗 */,
      pushLowObj: null /*推下级对象 */,
      pushLowNames: ["1", "2"] /*获取下级列表参数 */,
      schoolList: [] /*学校列表 */,
      selSchoolList: [] /*选择的下级列表 */,
      platform: "" /*可推送上级 */,
      pid: "" /*可推送上级id */,
      pushLowKeyword: "" /*关键词 */,
      platform_id: null /*记录平台id */,
      schoolcodeData: [] /**存放学校教育局列表 */,
      ids: [] /*存放被选中的视频列表 */,
      pushLowStatus: null /*记录是否批量推下级*/,
      pushUpStatus: null /*记录是否批量推上级 */,
      // videoTimer: null, // 刷新页面
      rowLen: 0,
    };
  },
  created() {
    this.getOrgnk();
    this.findAideoKind();
    this.getList();
    this.getOrgLevel2();
    this.getOrgLevel3();
    this.getSubject();
    // this.getMemory();
    this.get_schoolcode();
    if (this.$store.state.checkLevel) {
      this.platform_parent();
    }
  },
  // beforeDestroy() {
  //     this.videoTimer && clearInterval(this.videoTimer);
  // },
  watch: {
    "listParam.study_section_id": {
      handler(newVal, oldVal) {
        this.listParam.grade_id = null
        this.listParam.subject_id = null

        this.orgLevel3Param.pid = newVal;
        this.getOrgLevel3();

        this.subjectParam.org_id = newVal;
        this.getSubject();
      },
    },
    "listParam.grade_id": {
      handler(newVal, oldVal) {
        this.listParam.subject_id = null

        this.subjectParam.org_id = newVal;
        this.getSubject();
      },
    },
  },
  computed: {
    getMonth() {
      return (date) => {
        if (date == 0) {
          return "永久保存";
        } else {
          return date + "个月";
        }
      };
    },
  },
  methods: {
    getOrgnk() {
      let params = {
        app_code: this.app_code
      }
      let success = (res) => {
        this.allList = res.data.children
      };
      this.$ajax.get('api/network/get_org_subject', { params, func: { success } })
    },
    /**
     * 获取视频分类
     */
    findAideoKind() {
      let success = (res) => {
        this.typeOption = res.data;
        this.typeOption.unshift({ id: 0, name: "全部类型" });
      };
      this.$ajax.get("api/video/video_cate", { func: { success } });
    },

    /**
     * 获取服务器内存容量
     */
    getMemory() {
      let success = (res) => {
        let _name = +res.data[6].split("%")[0];

        if (_name >= 80) {
          this.memoryVisible = true;
        }
      };
      let fail = (res) => { };

      this.$ajax.get("api/system/system_info", {
        func: { success: success, fail: fail },
      });
    },
    searchFunc() {
      // this.listParam.status_m3u8 = this.status_m3u8;
      // this.listParam.cate_id = this.cate_id;
      this.listParam.platform_id = this.platform_id;
      this.$store.state.checkLevel && (this.listParam.grade_id = this.valueData[0]);
      this.$store.state.checkLevel && (this.listParam.subject_id = this.valueData[1]);
      this.listParam.page_index = 1;
      this.getList();
    },
    reset() {
      this.valueData = [];
      // this.status_m3u8 = -1
      // this.cate_id = ''
      this.platform_id = null;
      this.type = -1;
      this.listParam = {
        status_m3u8: -1,
        cate_id: 0,
        platform_id: null,
        study_section_id: null,
        grade_id: null,
        subject_id: null,
        keyword: "",
        page_index: 1,
        page_size: 10,
      };
      this.orgLevel2Param = {
        //获取学段参数
        level: 2,
        pid: null,
        direction: "balance",
      };
      this.orgLevel3Param = {
        //获取年级参数
        level: 3,
        pid: null,
        direction: "balance",
      };
      this.subjectParam = {
        //获取科目,版本，参数
        type: 2,
        org_id: null,
        status: 1,
      };

      this.getOrgLevel2();
      this.getOrgLevel3();
      this.getSubject();
      this.getList();
    },
    videoAdd() {
      let success = (res) => {
        if (res.data[17] === 0) {
          this.$router.push("/resources/video/new-video");
        } else {
          this.$message.error(
            "系统存储容量小于5G，请清理存储空间（视频/资源文件）或升级存储"
          );
        }
      };

      this.$ajax.get("api/system/system_info", { func: { success: success } });
    },
    // batchAdd(){
    //   let success = (res) => {
    //     if (res.data[17] === 0) {
    //       this.$router.push("/resources/video/batch-add");
    //     } else {
    //       this.$message.error(
    //         "系统存储容量小于5G，请清理存储空间（视频/资源文件）或升级存储"
    //       );
    //     }
    //   };

    //   this.$ajax.get("api/system/system_info", { func: { success: success } });
    // },
    videoEdit(item) {
      if (item.status_m3u8 == 1) {
        this.$router.push({
          path: "/resources/video/video-editing/" + item.id,
        });
      } else {
        this.$message.warning("视频转码中，不可进行编辑");
      }
    },
    viewClose() {
      this.showVideoPlayer = false;
      this.isActive = true;
    },
    videoView(obj) {
      this.loading.status = true;

      let success = (res) => {
        this.loading.status = false;
        this.playParam.play_url = res.data.play_url;
        this.showVideoPlayer = true;
        this.isActive = false;
      };
      let fail = (res) => {
        this.loading.status = false;
        this.$message.warning(res.msg);
      };
      //执行请求，并将回调方法变成config成员以便鉴权过期可以执行
      this.$ajax.get("api/video/check_view", {
        params: { id: obj.id },
        func: { success: success, fail: fail },
      });
    },
    // 序号
    typeIndex(index) {
      return (
        index + (this.listParam.page_index - 1) * this.listParam.page_size + 1
      );
    },
    getList() {
      this.loading.status = true;
      let success = (data) => {
        console.log(JSON.parse(JSON.stringify(data)), 11100000)
        this.loading.status = false;
        this.listData = data.data.data;
        this.total_number = data.data.data_sum;
      };
      let fail = (data) => {
        this.loading.status = false;
        this.$message.error(data.msg);
      };
      // this.getListRefresh();
      this.$ajax.get("api/video/video_list", {
        params: this.listParam,
        func: { success: success, fail: fail },
      });
    },
    // getListRefresh(){
    //       	let success = (data=>{
    //       		this.listData = data.data.data;
    //       		this.total_number = data.data.data_sum;
    //       	})

    //           this.videoTimer && clearInterval(this.videoTimer);
    //           this.videoTimer = setInterval(() => {
    //               this.getListRefresh();
    //           }, 180000);

    //       	this.$ajax.get('api/video/video_list',{params: this.listParam,func:{success}})
    //       },
    pushToTop() {
      var newTemp = [];
      newTemp.push(deep_clone(this.pushObj));
      var temp_ = {
        id: null,
        position: null,
        name: "",
        picture: "/static/default/video_cover.png",
      };
      var have_continued = false; //是否已经跳过第一个空的推首页项
      //去掉在里面的当前的推首页项
      for (var i = this.positionData.length - 1; i >= 0; i--) {
        if (
          parseInt(this.pushObj.resid) === parseInt(this.positionData[i].resid)
        ) {
          this.positionData[i] = deep_clone(temp_);
          break;
        }
      }
      for (var i = 0; i <= 7; i++) {
        //第一个空的推首页项,往后空的就不会跳过
        if (is_empty(this.positionData[i].id) && !have_continued) {
          have_continued = true;
          continue;
        }
        newTemp.push(deep_clone(this.positionData[i]));
        if (newTemp.length === 8) {
          break;
        }
      }
      this.home_flag = 0;
      this.ruleForm.selectIndex = 0;
      this.positionData = deep_clone(newTemp);
    },
    savePosition() {
      let success = (data) => {
        this.$message.success(data.msg);
        this.homeVisible = false;
      };
      //alert(this.pushObj.resid)
      var params = {
        id: [],
        position: [],
        resid: this.pushObj.resid,
        home_flag: this.home_flag,
      };
      for (var i = 0; i < this.positionData.length; i++) {
        if (!is_empty(this.positionData[i].resid)) {
          params.id.push(this.positionData[i].resid);
          params.position.push(i + 1);
        } else {
          params.id.push(null);
          params.position.push(null);
        }
      }
      this.$ajax.post("api/video/push_to_home", params, {
        func: { success: success },
      });
    },
    getPosition() {
      this.loading.status = true;
      let success = (data) => {
        this.loading.status = false;
        this.tempPositionData = data.data;
        this.ruleForm.selectIndex = null;
        this.renderPushHtml();
      };
      let fail = (data) => {
        this.loading.status = false;
        this.$message.error(data.msg);
      };
      //执行请求，并将回调方法变成config成员以便鉴权过期可以执行
      this.$ajax.get("api/video/video_home_position", {
        func: { success: success, fail: fail },
      });
    },
    renderPushHtml() {
      this.positionData = [];
      for (var i = 0; i <= 7; i++) {
        var temp_ = {
          id: null,
          position: i + 1,
          name: "",
          picture: "/static/default/video_cover.png",
        };
        for (var j = 0; j < this.tempPositionData.length; j++) {
          if (i + 1 === parseInt(this.tempPositionData[j].position)) {
            if (
              is_empty(this.ruleForm.selectIndex) ||
              (!is_empty(this.ruleForm.selectIndex) &&
                parseInt(this.pushObj.resid) !==
                parseInt(this.tempPositionData[j].resid))
            ) {
              temp_ = deep_clone(this.tempPositionData[j]);
            }
          }
        }
        if (this.ruleForm.selectIndex === i) {
          this.positionData.push(this.pushObj);
        } else {
          this.positionData.push(temp_);
        }
      }
      //取消首页置顶
      if (this.home_flag === 0 && this.ruleForm.selectIndex !== 0) {
        this.home_flag = 1;
      }
    },

    pushIndexBox(obj) {
      this.homeVisible = true;
      this.ruleForm.selectIndex = null;
      this.pushObj = {
        resid: obj.id,
        name: obj.name,
        picture: obj.picture,
        position: null,
        study_section_id: obj.study_section_id,
        grade_id: obj.grade_id,
      };
      this.getPosition();
    },
    deletePushIndex(inx) {
      this.positionData[inx].id = null;
      this.positionData[inx].position = null;
      this.positionData[inx].name = "";
      this.positionData[inx].picture = "/static/default/video_cover.png";
      var deletet_inx = -1;
      this.tempPositionData.forEach((item, inxx) => {
        if (parseInt(item.position) - 1 === inx) {
          deletet_inx = inxx;
        }
      });
      deletet_inx > -1 && this.tempPositionData.splice(deletet_inx);
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.savePosition();
        } else {
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.ruleForm.selectIndex = null;
      this.getPosition();
    },
    //获取学段
    getOrgLevel2() {
      let success = (data) => {
        this.orgLevel2 = data.data;
        this.orgLevel2.unshift({ id: null, name: "全部学段" });
      };
      this.$ajax.get("api/org/org", {
        params: this.orgLevel2Param,
        func: { success: success },
      });
    },
    //获取年级
    getOrgLevel3() {
      let success = (data) => {
        this.orgLevel3 = data.data;
        this.orgLevel3.unshift({ id: null, name: "全部年级" });
      };
      this.$ajax.get("api/org/org", {
        params: this.orgLevel3Param,
        func: { success: success },
      });
    },
    //获取科目
    getSubject() {
      let success = (data) => {
        this.orgSubject = data.data;
        this.orgSubject.unshift({ id: null, name: "全部科目" });
      };
      this.$ajax.get("api/cate/subject", {
        params: this.subjectParam,
        func: { success: success },
      });
    },
    handleSizeChange(val) {
      this.listParam.page_index = 1;
      this.listParam.page_size = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listParam.page_index = val;
      this.getList();
    },
    changeVideo(id, status) {
      let success = (data) => {
        this.$message.success(data.msg);

        if (status === 0) {
          if (this.listData.length - this.rowLen === 0) {
            if (this.listParam.page_index > 1) {
              this.listParam.page_index--;
            } else {
              this.listParam.page_index = 1;
            }
          }
        }

        this.getList();
      };
      this.$ajax.delete("api/video/video", {
        params: { videoid: id, status: status },
        func: { success: success },
      });
    },
    /**
     * 批量删除视频
     */
    deleteConfirm() {
      if (this.ids.length === 0) {
        this.$message.warning("请选择要删除的视频");
        return false;
      }

      const cancel = (res) => { };
      const yes = (res) => {
        this.rowLen = this.ids.length;
        this.deleteAllData(this.ids.join(","));
      };

      this.e_confirm({ yes, cancel, txt: "确定要删除选中的视频吗？" });
    },
    /**
     * 批量删除
     */
    deleteAllData(video_string) {
      let success = (res) => {
        this.$message.success(res.msg);

        if (this.listData.length - this.rowLen === 0) {
          if (this.listParam.page_index > 1) {
            this.listParam.page_index--;
          } else {
            this.listParam.page_index = 1;
          }
        }

        this.getList();
      };
      this.$ajax.delete("api/video/delete_some_video", {
        params: { video_string },
        func: { success: success },
      });
    },
    /**
     * 删除单个视频
     */
    deleteVideo_confirm(obj) {
      let yes = (data) => {
        this.rowLen = 1;
        this.changeVideo(obj.id, 0);
      };
      let cancel = (data) => { };
      this.e_confirm({
        yes: yes,
        cancel: cancel,
        txt: "确定将 " + obj.video_name + " 删除吗？",
      });
    },
    down(id) {
      var form = document.createElement("form");
      form.action = this.BASE_URL + "/index/resource/resourcedownload";
      form.method = "post";
      form.style.display = "none";

      var opt_id = document.createElement("textarea");
      opt_id.name = "id";
      opt_id.value = id;
      form.appendChild(opt_id);
      var opt_type = document.createElement("textarea");
      opt_type.name = "type";
      opt_type.value = 0;
      form.appendChild(opt_type);

      document.body.appendChild(form);
      form.submit();
      document.body.removeChild(form);
    },
    handleSelectionChange(val) {
      this.ids = [];
      if (val.length > 0) {
        val.forEach((item) => {
          this.ids.push(item.id);
        });
      }
    },
    pushLow(data) {
      /*推下级 */
      this.pushLowObj = data;
      this.pushLowStatus = null;
      this.pushLowFlag = true;
    },
    pushActive(flag) {
      if (flag) {
        if (this.selSchoolList.length <= 0) {
          this.$message.error("请选择要推送的下级");
          return;
        }
        let params = {
          id: [],
          res_type: "video",
          school_id: "",
          push_type: 2,
        };

        if (this.pushLowStatus) {
          params.id = this.ids;
        } else {
          params.id.push(this.pushLowObj.id);
        }

        let arr = [];
        this.selSchoolList.forEach((item) => {
          arr.push(item.id);
        });
        params.school_id = arr.join();
        const success = (res) => {
          this.$message.success(res.msg);
          this.pushLowHide();
          this.ids = [];
          this.getList();
        };
        const fail = (res) => {
          this.loading.status = false;
          this.$message.error(res.msg);
        };

        this.loading.status = true;
        this.$ajax.post("api/level/push_data", params, {
          func: { success: success, fail: fail },
        });
      } else {
        this.pushLowHide();
      }
    },
    pushLowAll() {
      /*批量推下级 */
      if (this.ids.length <= 0) {
        this.$message.error("请选择要推送的选项");
        return;
      }
      this.pushLowStatus = 1;
      this.pushLowFlag = true;
    },
    getPushLowList(list) {
      this.selSchoolList = list;
    },
    pushLowHide() {
      this.pushLowObj = null;
      this.pushLowFlag = false;
    },
    platform_parent() {
      /*获取可推送的上级 */
      const success = (res) => {
        if (!is_empty(res.data)) {
          this.platform = res.data.name;
          this.pid = res.data.id;
        }
      };
      this.$ajax.get("api/level/platform_parent", {
        params: {},
        func: { success: success },
      });
    },
    pushUp(video_id) {
      // let params = {
      // 	id: id,
      // 	res_type: 'video',
      // 	school_id: this.pid,
      // 	push_type: 1,
      // }
      // const success=res=>{
      // 	this.$message.success(res.msg)
      // 	this.ids = [];
      // 	this.getList();
      // }
      // this.$ajax.post("api/level/push_data", params, {
      // 	func: { success: success }
      // });
      let params = {
        video_id: video_id,
      };
      let success = (res) => {
        this.$message.success(res.msg);
        this.getList();
      };
      this.$ajax.post("api/video/video_push", params, {
        func: { success: success },
      });
    },
    pushUpTips(flag) {
      if (flag) {
        /*确定的逻辑 */
        if (this.ids.length > 1) {
          this.pushAll();
        } else {
          this.pushUp(this.video_id);
        }
        this.pushUpFlag = false;
      } else {
        this.pushUpFlag = false;
        return;
      }
    },
    pushUpTrigger(data) {

      this.video_id = data.id;
      this.videoForm = {
        video_name: data.video_name,
      };
      this.pushUpFlag = true;

      // let title = `是否要将资源推送至${this.platform}？（需经过审核）`;
      //  this.$confirm(title, '提示', {
      // 	confirmButtonText: '确定',
      // 	cancelButtonText: '取消',
      // 	type: 'warning'
      // 	}).then(() => {
      // 		if(data) {
      // 			let ids = [data.id];
      // 			this.pushUp(ids);
      // 		} else {
      // 			this.pushUp(this.ids);
      // 		}
      // 	}).catch(() => {
      // 	this.$message({
      // 		type: 'info',
      // 		message: '已取消推送'
      // 	});
      // });
    },
    get_schoolcode() {
      /*获取学校教育局 */
      let params = {
        app_code: sessionStorage.getItem("CheckSchoolAppCode"),
      };
      let success = (res) => {
        console.log(res, "pppp");
        this.schoolcodeData = res.data;
      };
      this.$ajax.get("api/group/get_platform_org", {
        params,
        func: { success },
      });
    },
    pushAll() {
      for (let i of this.ids) {
        this.pushUp(i);
      }
    },
    pushUpAll() {
      /*批量推上级 */
      if (this.ids.length <= 0) {
        this.$message.warning("请选择要推送的选项");
        return;
      }
      if (this.ids.length > 10) {
        this.$message.error("批量推送每次最多只能推送十项");
        return;
      }
      console.log(this.listData, this.ids);
      let nameArr = [];
      this.listData.forEach((item, index) => {
        this.ids.forEach((items, indexs) => {
          if (item.id == items) {
            console.log(items);
            nameArr.push(item.video_name);
          }
        });
      });
      this.videoForm.video_name = name = `( ${nameArr.join('、')} )`;
      this.pushUpFlag = true;
      // this.pushUpTrigger();
    },
    toLink(link) {
      this.$router.push(link);
    },
  },
  components: {
    videoAlertView,
    pushLowWin,
    dplayer,
  },
};
</script>
<style lang="scss">
.zh-video-list {
  .server-memory {
    display: flex;
    align-items: center;
    flex-direction: column;
    margin: 25px 0 45px;

    >img {
      margin-bottom: 25px;
    }
  }

  .el-table__body-wrapper table tbody {
    td:nth-child(8) {
      padding: 0;
    }
  }

  .home-page-t {
    margin-bottom: 20px;
    font-size: 12px;

    >span {
      color: #348efc;
    }
  }

  .el-radio+.el-radio {
    margin: 0;
  }

  .el-form-item {
    max-height: 500px;
    overflow: hidden;
    overflow-y: auto;
    padding-bottom: 20px;
  }

  .page-checked {
    width: 177px;
    height: 150px;
    overflow: hidden;
    margin-right: 10px !important;
    padding: 0;

    &:nth-of-type(4n) {
      margin-right: 0 !important;
    }

    .el-radio__input {
      position: absolute;
      bottom: 10px;
      left: 0;
    }

    .home-page-ls {
      >div {
        position: relative;
        width: 100%;
        height: 100px;
        overflow: hidden;
        margin-bottom: 10px;

        >img {
          width: 100%;
          height: 100%;
          object-fit: cover;
        }

        >i {
          position: absolute;
          right: 5px;
          top: 5px;
          // color: #348efc;
        }
      }

      >p {
        margin: 0;
        padding-left: 20px;
      }
    }
  }
}

.masking {
  display: block;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transition: 0.5s;
  background: rgba(0, 0, 0, 0.3);
  z-index: 4;

  .maskingBox {
    position: absolute;
    top: 20%;
    left: 50%;
    width: 800px;
    margin-left: -400px;
    background: #fff;
  }

  .masking_h {
    padding: 10px 15px;
    background: #348efc;
    text-align: center;
    text-align-last: justify;

    >span,
    >i {
      font-size: 16px;
      text-align-last: initial;
      display: inline-block;
      vertical-align: middle;
      color: #fff;
    }

    >i {
      cursor: pointer;
    }
  }

  .masking_ccc {
    padding: 15px;
    height: 450px;
  }
}

.activeLive {
  opacity: 0;
  visibility: hidden;
}

.videPAHT {
  color: #409eff;
  margin-right: 10px;
}

.push-low-title {
  width: 220px;
  margin-bottom: 15px;
}

.push-low-box {
  display: flex;

  .push-low-box-l {
    flex: 0 0 220px;
    margin-right: 10px;
    border-left: 1px solid #ebeef5;
    border-right: 1px solid #ebeef5;
    max-height: 400px;
    overflow: hidden;
    overflow-y: auto;

    .el-collapse {
      padding: 0 10px;

      li {
        text-align: center;
        cursor: pointer;

        &:hover {
          background: #ddd;
        }
      }
    }
  }

  .push-low-box-r {
    flex: 1;
    border: 1px solid #ebeef5;
    max-height: 400px;
    overflow: hidden;
    overflow-y: auto;

    .list-head {
      height: 48px;
      line-height: 48px;
    }

    ul {
      display: flex;

      li {
        text-align: center;

        &:first-child {
          flex: 0 0 50px;
        }

        &:nth-of-type(2) {
          flex: 0 0 50px;
        }

        &:nth-of-type(3) {
          flex: 1;
        }
      }

      .el-icon-close {
        color: #f56c6c;
        cursor: pointer;
      }
    }
  }
}
</style>
